package com.xiaodou.mjf.web.xface.core.controller.v2;

import com.google.common.collect.Maps;
import com.xiaodou.mjf.infrastructure.common.utils.StringUtils;
import com.xiaodou.mjf.web.xface.core.utils.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.Map;

/**
 * Created by Rocky on 15/3/31.
 */
@Controller("com.xiaodou.mjf.web.xface.core.controller.v2.H5PaymentController")
@RequestMapping("v2/core")
public class H5PaymentController {

    @RequestMapping("payment/h5.html")
    public String payment(HttpServletRequest request,HttpServletResponse response,Model model){

        Map<String,String> params = Maps.newHashMap();
        Enumeration<String> paramNames = request.getParameterNames();
        while(paramNames.hasMoreElements()){
            String paramName = paramNames.nextElement();
            params.put(paramName,request.getParameter(paramName));
        }

        if(!params.containsKey(Param.sign) || StringUtils.isBlank(params.get(Param.sign))){
            model.addAttribute("code","1001");
            model.addAttribute("message","请求报文需包含签名数据");
            return "pay/v2/h5.html";
        }



        return null;
    }
}
